<template>
  <div class="home">
  
  </div>
</template>

<script>
/*
axios ；get post put patch
get 获取数据
post 提交
put 更新 所有数据推送到后端   修改
patch 跟新 只推送修改的   表单数据多
delete 删除
*/
import axios from 'axios'
export default {
  name: 'axios2-2',
  components: {
  },
  created(){
      //http://localhost:8080//data.json?id=12
    axios.get('/data.json',{params:{id:12}}).then((res)=>{
      console.log(res)
    })
    //get
    axios({
        method:'get',
        url:'/cache/get',
        params:{key:'b'}
    }).then(res=>{
         console.log(res)
    })
    let data = {key:'post'}
    //post  
    //form-data表单提交 可以文件上传
    let formdata = new FormData()
    for(let key in data){
      formdata.append(key,data[key])
    }
     axios.post('/cache/post',formdata).then((res)=>{
    console.log('psot+formdata='+res)
    })
    //application/json
    axios.post('/cache/post',data).then((res)=>{
    console.log('psot+application/json-1'+res)
    })
    axios({
      method:'post',
      url:'/cache/post',
      data:data
    }).then(res=>{
         console.log('psot+application/json-2'+res)
    })

     //put
    axios.put('/cache/put',data).then((res)=>{
    console.log('put+application/json-1'+res)
    })

    //delete  params（url拼接）  与 data（请求体）
    axios.delete('/cache/delete',{params: data})
    axios.delete('/cache/delete',{data: data})
  }
}
</script>
